const HtmlWebpackPlugin = require("html-webpack-plugin")
const webpack = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const data = require('./data.json')
const path = require('path')
module.exports= {
  mode:"development",
  entry: "./index.jsx",
  output: {
    filename: "main.js"
  },
  devServer:{
    contentBase:path.join(__dirname,"dist"),
    compress:true,
    port:9000,
    before(app){
      app.get('/api/data',function (req,res) {
        res.json(data)
      })
    },
    proxy: {
      '/cross': {
        target: 'http://localhost:9001',
        pathRewrite: {'^/cross' : ''}
      }
    }

// }
  },
  module: {
    rules: [
      // {test:/\.js[x]?$/,
      // // use:{loader:"babel-loader",options:{presets:["@babel/preset-react",@babel/preset-env"]}}
      // loader:"babel-loader?presets[]=@babel/preset-env&presets[]=@babel/preset-react"
      // },
      // {
      //   test: /\.js[x]?$/,
      //   exclude: /(node_modules|bower_components)/,
      //   use: [{
      //     loader: "babel-loader",
      //     options: {presets: ["@babel/preset-env", "@babel/preset-react"]}
      //   }]
      // },
      {test:/\.js[x]?$/,loader:"babel-loader?presets[]=@babel/preset-env&presets[]=@babel/preset-react"},
      {test:/\.scss$/,loader:"style-loader!css-loader?modules!sass-loader"},
      {test:/\.(png|jpg)$/,loader:"url-loader?limit=8192"}
    ]
  },
  optimization: {  //压缩的更加精致
  minimizer: [
    new UglifyJsPlugin({ /* your config */ })
  ]
},
  plugins:[
      new HtmlWebpackPlugin({
        template: "./template.html",
        minify:{
          collapseWhitespace:true,
          removeAttributeQuotes:true,
          removeComments:true
        },
      }),
    new webpack.DefinePlugin({
      value1:"'hello world'",
      value2:"123"
    }),
    new webpack.HotModuleReplacementPlugin()

  ]
}








